<?php              
				include "includes".DIRECTORY_SEPARATOR."start_session.php";

				if ( !defined('USERNAME') || !defined('GROUP') || GROUP != "admin" )
				{
					header("Location: index.php");
					exit;
				}

  				 $tablou = array("nume" => "",
								 );
					
				$color = array("nume" => "#333333",
								 );	
				
								 		
				 $erori = "";
				 
				 $tablou_erori = array("nume1" => "Nu a fost introdus numele<br />",
				 				 "nume2" => "Nume introdus invalid<br />",
								 );
  
  
  
              
				   
  				  $form_get=<<<GATA
	                   <form method = POST action = "manage_groups.php">
	                   <table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
	                   <tr><td><b>Nume</b></td><td><input type = "text" name = "nume" value='$tablou[nume]' size="40" maxlength="35" ></td></tr>
					   <tr><td></td><td><input type ="submit" value = "Adauga grup" ></td></tr>
					   
					   </table>
	                   </form>
GATA;


			   if($_SERVER['REQUEST_METHOD'] == 'GET')
			   {
				   	echo $form_get;
			   }
  
 
  
  
  				  if($_SERVER['REQUEST_METHOD'] == 'POST')
				  
				  {
				  		$ok = 1;
								
							#verifica numele
							if(empty($_POST["nume"]))
							{
									$erori = $erori.$tablou_erori["nume1"];
									$ok = 0;
									$color["nume"] = "red";
							}
							else if((preg_match('/^[A-Za-z]+([ ,\'][A-Za-z-]+)*$/',$_POST["nume"])) == 0)
							{
									$erori = $erori.$tablou_erori["nume2"];
									$ok = 0;		
									$color["nume"] = "red";								
							}
							else
							{
									$tablou["nume"] = $_POST["nume"];  		
							}
								
							if($ok != 1)
							{
						
					   			$form_post=<<<GATA
			                   <form method = POST action = "manage_groups.php">
			                   <table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
			                   <tr><td><b><font color='$color[nume]'>Nume</font></b></td><td><input type = "text" name = "nume" value='$tablou[nume]' size="40" maxlength="35" ></td></tr>
							   <tr><td></td><td><input type = submit value = "Adauga Grup" ></td></tr>
					   
							   </table>
	            		       </form>
GATA;
					 			echo $form_post;
								echo "<font color=\"red\">".$erori."</font>";
							}
							else  
							{
									require_once ('mysql_connect.php');
									$u = mysqli_query($dbc,"INSERT INTO groups (group_name) VALUES ('$tablou[nume]')");
									
									echo "<br />";	
									echo "<center><h2><font color=\"#00CC00\">Grupul a fost adaugat cu succes ! </font></h2></center>";	
									
									echo "<br />";	
									echo $form_get;
							}
							
					}
						
?>


